//
//  NSMutableDictionary+HACShield.m
//  HACShield
//
//  Created by Chengjie on 2019/5/22.
//

#import "NSMutableDictionary+HACShield.h"
#import "NSObject+HACSwizzling.h"

@implementation NSMutableDictionary (HACShield)

/**
__NSDictionaryM
 */
+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        SEL sel_set_obj = @selector(setObject:forKey:);
        hac_swizzleInstanceMethod(hac_getClass(@"__NSD", @"ictionaryM"), sel_set_obj, @selector(hac_setObject:forKey:));
        SEL sel_remove_obj = @selector(removeObjectForKey:);
        hac_swizzleInstanceMethod(hac_getClass(@"__NSD", @"ictionaryM"), sel_remove_obj, @selector(hac_removeObjectForKey:));
        SEL sel_add_entries = @selector(addEntriesFromDictionary:);
        hac_swizzleInstanceMethod(hac_getClass(@"__NSD", @"ictionaryM"), sel_add_entries, @selector(hac_addEntriesFromDictionary:));
    });
}

- (void)hac_setObject:(id)anObject forKey:(id<NSCopying>)aKey {
    if (anObject && aKey){
        [self hac_setObject:anObject forKey:aKey];
    }
}

- (void)hac_removeObjectForKey:(id)aKey {
    if (aKey) {
        [self hac_removeObjectForKey:aKey];
    }
}

- (void)hac_addEntriesFromDictionary:(NSDictionary *)otherDictionary {
    if (otherDictionary && [otherDictionary isKindOfClass:[NSDictionary class]]) {
        if (otherDictionary.count > 0) {
            [self hac_addEntriesFromDictionary:otherDictionary];
        }
    }
}

@end
